<?php
require_once(LIB.'database.php');


class User extends DatabaseObject{
	
	protected static $table_name = 'users';
	public $id = "";
	public $username = "";
	public $password = "";
	public $first_name = "";
	public $last_name = "";
	
	 
	public static function find_by_id($id = 1){
		return self::find_by_sql("Select * from users where id=".$id);
	}
	
	protected static function instantiate($record){
		$object = new self();
		foreach($record as $attribute=>$value){
			if($object->has_attribute($attribute)){
				$object->$attribute = $value;
			}
		}
		return $object;
	}
	private function has_attribute($attribute){
		$object_vars = get_object_vars($this);
		return array_key_exists($attribute, $object_vars);
	}
	public static function authenticate($username = "", $password = ""){
		$found_user = self::find_by_sql("Select * from ".self::$table_name.";");
		if(count($found_user)> 0){
		return array_shift($found_user);
		}
		else {
			return false;
		}
	}
}
?>